FROM golang AS build

RUN mkdir /build
WORKDIR /build
RUN adduser -u 10001 app-runner

ENV GOPROXY https://goproxy.cn
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -o ecology .

FROM alpine as final
RUN mkdir /app
WORKDIR /app
COPY --from=build /build/ecology /app/
COPY --from=BUILD /etc/passwd /etc/passwd

USER app-runner
ENTRYPOINT [ "/app/ecology" ]